package com.forezp.datastruct.singleLinkList;

import java.util.Arrays;

/**
 *
 * Created by forezp on 2017/12/12.
 */
public class ReverseSingleLinkList {

    public static Node reverseNode(Node head) {
        if (head == null) {
            return null;
        }
        if (head.getNext() == null) {
            return head;
        }
        Node newNode = reverseNode(head.getNext());
        head.getNext().setNext(head);
        head.setNext(null);
        return newNode;

    }

    public static void main(String[] args) {
        Node.printNode(reverseNode(SingeLinkListCreater.
                createLinkList(Arrays.asList(1,2,3,4,5))));
    }
}
